//
//  MakeSchemeDiseaseTableViewCell.m
//  AnXin100
//
//  Created by Sakura on 2018/11/10.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "MakeSchemeDiseaseTableViewCell.h"
#import "JJOptionView.h"
#import "NSString+Size.h"
@interface MakeSchemeDiseaseTableViewCell ()

@property (nonatomic, strong) JJOptionView *selecView;

@property (nonatomic, strong) UITextField *dosageTF;

@property (nonatomic, strong) UITextField *useExplainTF;

@property (nonatomic, strong) UITextField *nameTF;

@property (nonatomic, strong) UIView *line1;

@property (nonatomic, strong) UIView *line2;

@property (nonatomic, strong) UIView *line3;

@end

@implementation MakeSchemeDiseaseTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self creatView];
        [self setlayout];
    }
    return self;
}

- (void)creatView {
    
    self.bgView = [[UIView alloc]init];
    self.bgView.cornerRadius = 5;
    self.bgView.borderColor = COLOR_GREEN;
    self.bgView.borderWidth = 1;
    self.bgView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.bgView];
    
//    self.titleLabel = [[UILabel alloc]init];
//    self.titleLabel.textAlignment = NSTextAlignmentLeft;
//    self.titleLabel.text = @"病害防治施肥方案";
//    self.titleLabel.font = FONT_FOURTEEN;
//    self.titleLabel.textColor = COLOR_DIV;
//    [self.bgView addSubview:self.titleLabel];
    
    self.contentLabel1 = [[UILabel alloc]init];
    self.contentLabel1.text = @"肥料名称:";
    self.contentLabel1.font = FONT_FOURTEEN;
    self.contentLabel1.textColor = COLOR_Gray;
    [self.bgView addSubview:self.contentLabel1];
    
    self.contentLabel2 = [[UILabel alloc]init];
    self.contentLabel2.text = @"使用方法";
    self.contentLabel2.font = FONT_FOURTEEN;
    self.contentLabel2.textColor = COLOR_Gray;
    [self.bgView addSubview:self.contentLabel2];
    
    self.contentLabel3 = [[UILabel alloc]init];
    self.contentLabel3.text = @"亩用药量(kg):";
    self.contentLabel3.font = FONT_FOURTEEN;
    self.contentLabel3.textColor = COLOR_Gray;
    [self.bgView addSubview:self.contentLabel3];
    
    
    self.contentLabel5 = [[UILabel alloc]init];
    self.contentLabel5.text = @"施肥补充说明:";
    self.contentLabel5.font = FONT_FOURTEEN;
    self.contentLabel5.textColor =COLOR_Gray;
    [self.bgView addSubview:self.contentLabel5];
    
    
    _selecView = [[JJOptionView alloc] init];
    _selecView.dataSource = @[@"111",@"222",@"333",@"444",@"555"];
    _selecView.titleFontSize = 12;
    _selecView.title = @"施肥";
    _selecView.selectedBlock = ^(JJOptionView * _Nonnull optionView, NSInteger selectedIndex) {
        NSLog(@"%@",optionView);
        NSLog(@"%ld",selectedIndex);
    };
    [self.bgView addSubview:self.selecView];
    
    _nameTF = [UITextField new];
    _nameTF.font = FONT_TWELVE;
    _nameTF.placeholder = @"微生物菌肥";
    [self.bgView addSubview:_nameTF];
    
    _dosageTF = [UITextField new];
    _dosageTF.font = FONT_TWELVE;
    _dosageTF.placeholder = @"请填写亩用量";
    [self.bgView addSubview:_dosageTF];
    
    _useExplainTF = [UITextField new];
    _useExplainTF.font = FONT_TWELVE;
    _useExplainTF.placeholder = @"请填写使用说明";
    [self.bgView addSubview:_useExplainTF];
    
    _line1 = [UIView new];
    _line1.backgroundColor = COLOR_GREEN;
    [_bgView addSubview:_line1];
    
    _line2 = [UIView new];
    _line2.backgroundColor = COLOR_GREEN;
    [_bgView addSubview:_line2];
    
    _line3 = [UIView new];
    _line3.backgroundColor = COLOR_GREEN;
    [_bgView addSubview:_line3];
}

- (void)setlayout {
    
    self.bgView.sd_layout
    .leftSpaceToView(self.contentView, 10)
    .topSpaceToView(self.contentView, 5)
    .widthIs(SCREEN_WIDTH-20)
    .heightIs(100);
    
//    self.titleLabel.sd_layout
//    .leftSpaceToView(self.bgView, 10)
//    .topSpaceToView(self.bgView, 10)
//    .widthIs(SCREEN_WIDTH-40)
//    .heightIs(20);
    

    
    CGFloat w1 = [_contentLabel1.text textSizeWithFont:FONT_FOURTEEN limitWidth:SCREEN_WIDTH].width;;
    CGFloat w2 = [_contentLabel2.text textSizeWithFont:FONT_FOURTEEN limitWidth:SCREEN_WIDTH].width;
    CGFloat w3 = [_contentLabel3.text textSizeWithFont:FONT_FOURTEEN limitWidth:SCREEN_WIDTH].width;
    CGFloat w5 = [_contentLabel5.text textSizeWithFont:FONT_FOURTEEN limitWidth:SCREEN_WIDTH].width;

    self.contentLabel1.sd_layout
    .leftSpaceToView(self.bgView, 10)
    .topSpaceToView(self.bgView, 10)
    .widthIs(w1)
    .heightIs(20);
    
    _nameTF.sd_layout
    .leftSpaceToView(self.contentLabel1, 5)
    .heightIs(20)
    .topEqualToView(self.contentLabel1)
    .widthIs((SCREEN_WIDTH-20-30)/2 - w1 - 5);
    
    _line1.sd_layout
    .leftSpaceToView(self.bgView, 0)
    .rightSpaceToView(self.bgView, 0)
    .topSpaceToView(self.contentLabel1, 4.5)
    .heightIs(1);
    
    self.contentLabel2.sd_layout
    .leftSpaceToView(_nameTF, 10)
    .topSpaceToView(self.contentLabel1, 10)
    .widthIs(w2)
    .heightRatioToView(self.contentLabel1, 1);

    self.contentLabel3.sd_layout
    .leftSpaceToView(self.bgView, 10)
    .topSpaceToView(self.contentLabel1, 10)
    .widthIs(w3)
    .heightRatioToView(self.contentLabel1, 1);

    _dosageTF.sd_layout
    .leftSpaceToView(self.contentLabel3, 5)
    .heightIs(20)
    .topEqualToView(self.contentLabel3)
    .widthIs((SCREEN_WIDTH-20-30)/2 - w3 - 5);
    
    _line2.sd_layout
    .leftSpaceToView(self.bgView, 0)
    .rightSpaceToView(self.bgView, 0)
    .topSpaceToView(self.contentLabel2, 4.5)
    .heightIs(1);
    
    self.contentLabel5.sd_layout
    .leftSpaceToView(self.bgView, 10)
    .topSpaceToView(self.contentLabel3, 10)
    .widthIs(w5)
    .heightRatioToView(self.contentLabel1, 1);
    
    _useExplainTF.sd_layout
    .leftSpaceToView(self.contentLabel5, 5)
    .rightSpaceToView(self.bgView, 5)
    .topEqualToView(self.contentLabel5)
    .heightIs(20);
    
    [self.bgView layoutIfNeeded];
    [self.bgView setNeedsLayout];
    
    _selecView.sd_layout
    .leftSpaceToView(self.contentLabel2, 5)
    .rightSpaceToView(self.bgView, 5)
    .heightIs(20)
    .topEqualToView(self.contentLabel2);
    
    _line3.sd_layout
    .widthIs(1)
    .topSpaceToView(_line1, 0)
    .bottomSpaceToView(_line2, 0)
    .leftSpaceToView(_dosageTF, 4.5);
    
    [self setupAutoHeightWithBottomView:self.bgView bottomMargin:10];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
